﻿@{
    ViewBag.Title = "项目概况";
    Layout = "~/Views/Shared/_indexBase1.5.cshtml";
    if (false)
    {
        <script src="~/LiberUI/Scripts/jquery-2.0.3.js"></script>
        <script src="~/LiberUI/Scripts/jquery.ba-resize.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Base.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Controllers.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Action.js"></script>
        <script src="~/SiteUI/BaseScripts/site.js"></script>
    }
}
<link href="~/SiteUI/Project/Project.css" rel="stylesheet" />

@section HeadCnt{
    <div class="MiddleWraper">
        <h2 class="index_Title">@ViewBag.Title</h2>
        <h3>展示项目及相关信息</h3>
    </div>
}
@section HeadBar{
    <div id="Tools" class="LeftWraper">
        <div id="Add">新建项目</div>
    </div>
}

@section LeftNavi{
    <div id="lstProjs">

    </div>
}
<div id="ProjDetail">
    <div id="Base" class="InfoBlock">
        <span id="txbName" class="BlockTitle">项目名称</span>
        <pre id="txbDescribe"></pre>
        <div id="BaseTools">
            <div id="btnEdit">编辑</div>
            @*<div id="btnDelete">删除</div>*@
        </div>
    </div>
    <div id="ProjMember" class="InfoBlock">
        <span class="BlockTitle">项目成员信息</span>
    </div>
    <div id="Feedback" class="InfoBlock">
        <span class="BlockTitle">相关反馈和事务</span>
    </div>
    <div id="SubProj" class="InfoBlock">
        <span class="BlockTitle">子项目相关信息</span>
    </div>
</div>

<div id="tmp">
    @RenderPage("/SiteUI/Project/wgProject.cshtml")
</div>
<script>
    Env.mode = "";
    function onProjClick(ev) {
        Env.CProj = ev.Data;
        //TODO:在右侧以各种可扩展部件方式展示项目相关信息
        //准备项目基础信息栏目
        $("#txbName").text(Env.CProj.Name);
        $("#txbDescribe").html(unescape(Env.CProj.Describe));
    };
    function onEditClick() {
        if (Env.CProj != null) {
            Env.mode = "update";
            //弹出标准项目编辑窗口
            wgProject.WndProjectEdit.show();
            wgProject.frmProjectEdit.val(Env.CProj);
        }
        else {
            alert('请选择一个项目再执行编辑');
        }
    };
    function onAddClick() {
        Env.mode = "new";
        wgProject.WndProjectEdit.show();
    };

    function onSubmit(ev) {
        wgProject.WndProjectEdit.dom().Mask().addClass('saving');
        var np = ev.target.val();
        if (Env.mode == "new") {
            new AjaxHelper("post", "/Project/New", np, newEnd, np);
        }
        else if (Env.mode == "update") {
            new AjaxHelper("post", "/Project/Update", np, updateEnd);
        }
    };

    function newEnd(rtn) {
        wgProject.WndProjectEdit.dom().Unmask();
        wgProject.WndProjectEdit.hide();
        if (rtn.IsPositive) {
            Env.lstProjs.Append(rtn.Data);
            wgProject.mnuProjects.Menu().Append(rtn.Data);
        }
    };
    function updateEnd(rtn) {
        wgProject.WndProjectEdit.dom().Unmask();
        wgProject.WndProjectEdit.hide();
        if (rtn.IsPositive) {
            //TODO:如果改变了父级，需要更新整棵树？太傻了吧，如何高效获知哪些节点需要更新？
            Env.lstProjs.Update('IDStr', rtn.Data);
            wgProject.mnuProjects.Menu().Update('IDStr', rtn.Data);
        }
        else {
            alert('更新失败，错误描述如下：'+rtn.Data);
        }
    };

    $(function () {
        //准备项目树
        Env.lstProjs = new List($("#lstProjs"),{ShowHead:false,ShowFoot:false,Selectble:true,StyleForSlcted:'slctedProj',Scroller:true});
        Env.lstProjs.af_makeView = function (_data) {
            return $("<div class='projItem'>").text(_data.Name);
        };
        var projs = '@ViewBag.MyProjects'.ToJSON();
        if (projs&&projs.length > 0) {
            Env.lstProjs.Append(projs);
        }
        else {
            
        }

        Env.lstProjs.on('itemClick', onProjClick);

        $("#Add").on("click", onAddClick);
        wgProject.frmProjectEdit.on("submit", onSubmit);

        //准备父级项目选择菜单的数据
        wgProject.mnuProjects.Menu().Append(projs);

        //准备基础信息栏目的编辑功能
        Env.Base = {};
        Env.Base.btnEdit = new Button($("#btnEdit")).on('click', onEditClick);
    })
</script>
